/**
 * Created by Arter_li on 2015/5/6.
 */
var WechatAPI = require('wechat-api');
var api = new WechatAPI(C('wechat_id'),C('wechat_secret'));
var crypto = require('crypto');
module.exports = Controller("Home/BaseController",function(){
    'use strict';
    return {
        indexAction:function(){

            var signature = this.get("signature");
            var timestamp = this.get("timestamp");
            var nonce = this.get("nonce");
            var token = "cmswing";
            var tmpArr = [token,timestamp,nonce].sort().join("");
            var tmpStr = crypto.createHash('sha1').update(tmpArr + '').digest('hex');
            if(tmpStr == signature){
                var echoStr = this.get("echostr");
                this.end(echoStr);
            }else{
                this.end("haha");
            }


             // console.log(crypto);
           // console.log(client.getAuthorizeURL("fsdaf","fasdfdsaf"))
           // api.shorturl('http://mp.weixin.com', function(err,res){
            //     console.log(res)
            //    console.log(err)
            //});
            //console.log(api)
            // this.end()
        },
        weixinAction:function(){
            //api.getIp(function(err,result){
            //    console.log(err);
            //    console.log(result);
            //});
            //api.getGroups(function(err,result){
            //    console.log(err);
            //    console.log(result);
            //});
            var self=this;

            //api.createLimitQRCode(100, function(err,res){
            //    console.log(res);
            //   var ttt= api.showQRCodeURL(res.ticket);
            //
            //    console.log(ttt);
            //});
            api.deliverNotify({
                "appid" : C('wechat_id'),
                    "openid" : C('wechat_secret'),
                    "transid" : "111112222233333",
                    "out_trade_no" : "555666uuu",
                    "deliver_timestamp" : "1369745073",
                    "deliver_status" : "1",
                    "deliver_msg" : "ok",
                    "app_signature" : "53cca9d47b883bd4a5c85a9300df3da0cb48565c",
                    "sign_method" : "sha1"
            }, function(a,b){

              console.log(a);
                console.log(b);

            });
           this.end();
        }
    }
})